package cn.tedu.start.controller;

import cn.tedu.commons.response.JsonResult;
import cn.tedu.pojo.dto.trolley.TrlyAddDTO;


import cn.tedu.service.trolley.ITrolleyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/trolley")
public class trolleyController {
    @Autowired
    private ITrolleyService trolleyService;
    //新增  hs
    @PostMapping("/add")
    public JsonResult addTrly(@Validated
                              @RequestBody
                                          TrlyAddDTO trlyAddDTO){
        System.out.println(trlyAddDTO);
        trolleyService.addTrly(trlyAddDTO);
        return JsonResult.ok("添加到购物车完成");
    }

    // 根据用户指定的购物车id删除购物车信息]
    @GetMapping("/delete")
    public JsonResult deleteByUserIds( Long id){
        System.out.println(id);
        trolleyService.trolleyByUserId(id);

        return JsonResult.ok("删除完成");
    }

    //根据用户id查询购物信息
    @GetMapping("/one")
    public JsonResult oneById(Long id){
        return trolleyService.selectTrly(id);


    }
    //根据id修改订单信息
    @GetMapping("/update")
    public JsonResult updateById(Long id,Long commodityNumber){
        System.out.println(id);
        trolleyService.updateTrly(id,commodityNumber);
        return JsonResult.ok("修改完成");

    }

}
